package com.example.springboot.controller;

import com.example.springboot.service.OneCircularDependencyService;
import com.example.springboot.service.TwoCircularDependencyService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * http://localhost:/8080/api/test/circular/dependency
 * 循环依赖使用@Autowrid或者@Resource
 * 不能使用构造方法
 */
@RestController
public class CircularDependencyController {

    private final OneCircularDependencyService oneCircularDependencyService;
    private final TwoCircularDependencyService twoCircularDependencyService;

    public CircularDependencyController(OneCircularDependencyService oneCircularDependencyService,
                                        TwoCircularDependencyService twoCircularDependencyService) {
        this.oneCircularDependencyService = oneCircularDependencyService;
        this.twoCircularDependencyService = twoCircularDependencyService;
    }

    @GetMapping("/api/test/circular/dependency")
    public String circularDependency(){
        return twoCircularDependencyService.getOneCircularDependency()
                + "-" + oneCircularDependencyService.getTwoCircularDependency();
    }
}
